<?php

/**
 * $Id$
 */
class MTintuc extends TV_Model {

    protected $table = "tin_tuc";    
     protected $table_nha_dat = "nha_dat";  
     protected $table_noi_ngoai_that = "noi_ngoai_that";
     protected $table_gioi_thieu = "gioi_thieu";
     protected $table_du_an = "du_an";
     protected $table_nha_mau = "nha_mau";
     protected $table_lien_he = "lien_he";

    function MTintuc() {
        parent::TV_Model();
        //$this->selectDetails();
    }
    //all function for tin tuc
    public function findAllNews($status = AppContants::ACTIVE_STATUS)
    {
        $sql = "SELECT {$this->table}.*
                FROM	{$this->table}                
                WHERE	status = ?
                ORDER BY id";

        return $this->query_array($sql, array($status));
    }
    public function getInforNewsById($id,$status=  AppContants::ACTIVE_STATUS){
        $sql = "SELECT {$this->table}.*
                FROM	{$this->table}                
                WHERE {$this->table}.id = ?
                        AND status = ?";

        return $this->query_row($sql, array($id,$status));
    }
    public function addTinTuc($data) {
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }
    public function updateNews($data, $id) {
        $where = "id = '$id'";
        $sql = $this->db->update_string($this->table, $data, $where);
        return $this->db->query($sql);
    }
     //all function for noi ngoai that
    public function findAllNoithat($status = AppContants::ACTIVE_STATUS)
    {
        $sql = "SELECT {$this->table_noi_ngoai_that}.*
                FROM	{$this->table_noi_ngoai_that}                
                WHERE	status = ?
                ORDER BY id";

        return $this->query_array($sql, array($status));
    }
    public function getInforNoithatById($id,$status=  AppContants::ACTIVE_STATUS){
        $sql = "SELECT {$this->table_noi_ngoai_that}.*
                FROM	{$this->table_noi_ngoai_that}                
                WHERE {$this->table_noi_ngoai_that}.id = ?
                        AND status = ?";

        return $this->query_row($sql, array($id,$status));
    }
    public function addNoithat($data) {
        $this->db->insert($this->table_noi_ngoai_that, $data);
        return $this->db->insert_id();
    }
    public function updateNoithat($data, $id) {
        $where = "id = '$id'";
        $sql = $this->db->update_string($this->table_noi_ngoai_that, $data, $where);
        return $this->db->query($sql);
    }
     //all function for nha dat
    public function findAllNhadat($status = AppContants::ACTIVE_STATUS)
    {
        $sql = "SELECT {$this->table_nha_dat}.*
                FROM	{$this->table_nha_dat}                
                WHERE	status = ?
                ORDER BY id";

        return $this->query_array($sql, array($status));
    }
    public function getInforNhadatById($id,$status=  AppContants::ACTIVE_STATUS){
        $sql = "SELECT {$this->table_nha_dat}.*
                FROM	{$this->table_nha_dat}                
                WHERE {$this->table_nha_dat}.id = ?
                        AND status = ?";

        return $this->query_row($sql, array($id,$status));
    }
    public function addNhadat($data) {
        $this->db->insert($this->table_nha_dat, $data);
        return $this->db->insert_id();
    }
    public function updateNhadat($data, $id) {
        $where = "id = '$id'";
        $sql = $this->db->update_string($this->table_nha_dat, $data, $where);
        return $this->db->query($sql);
    }
     //all function for gioi thieu
    public function findAllGioithieu($status = AppContants::ACTIVE_STATUS)
    {
        $sql = "SELECT {$this->table_gioi_thieu}.*
                FROM	{$this->table_gioi_thieu}                
                WHERE	status = ?
                ORDER BY id";

        return $this->query_array($sql, array($status));
    }
    public function getInforGioithieuById($id,$status=  AppContants::ACTIVE_STATUS){
        $sql = "SELECT {$this->table_gioi_thieu}.*
                FROM	{$this->table_gioi_thieu}                
                WHERE {$this->table_gioi_thieu}.id = ?
                        AND status = ?";

        return $this->query_row($sql, array($id,$status));
    }
    public function addGioithieu($data) {
        $this->db->insert($this->table_gioi_thieu, $data);
        return $this->db->insert_id();
    }
    public function updateGioithieu($data, $id) {
        $where = "id = '$id'";
        $sql = $this->db->update_string($this->table_gioi_thieu, $data, $where);
        return $this->db->query($sql);
    }
     //all function for du an
    public function findAllDuan($status = AppContants::ACTIVE_STATUS)
    {
        $sql = "SELECT {$this->table_du_an}.*
                FROM	{$this->table_du_an}                
                WHERE	status = ?
                ORDER BY id";

        return $this->query_array($sql, array($status));
    }
    public function getInforDuanById($id,$status=  AppContants::ACTIVE_STATUS){
        $sql = "SELECT {$this->table_du_an}.*
                FROM	{$this->table_du_an}                
                WHERE {$this->table_du_an}.id = ?
                        AND status = ?";

        return $this->query_row($sql, array($id,$status));
    }
    public function addDuan($data) {
        $this->db->insert($this->table_du_an, $data);
        return $this->db->insert_id();
    }
    public function updateDuan($data, $id) {
        $where = "id = '$id'";
        $sql = $this->db->update_string($this->table_du_an, $data, $where);
        return $this->db->query($sql);
    }
     //all function for nha mau
    public function findAllNhamau($status = AppContants::ACTIVE_STATUS)
    {
        $sql = "SELECT {$this->table_nha_mau}.*
                FROM	{$this->table_nha_mau}                
                WHERE	status = ?
                ORDER BY id";

        return $this->query_array($sql, array($status));
    }
    public function getInforNhamauById($id,$status=  AppContants::ACTIVE_STATUS){
        $sql = "SELECT {$this->table_nha_mau}.*
                FROM	{$this->table_nha_mau}                
                WHERE {$this->table_nha_mau}.id = ?
                        AND status = ?";

        return $this->query_row($sql, array($id,$status));
    }
    public function addNhamau($data) {
        $this->db->insert($this->table_nha_mau, $data);
        return $this->db->insert_id();
    }
    public function updateNhamau($data, $id) {
        $where = "id = '$id'";
        $sql = $this->db->update_string($this->table_nha_mau, $data, $where);
        return $this->db->query($sql);
    }
     //all function for lien he
    public function findAllLienhe($status = AppContants::ACTIVE_STATUS)
    {
        $sql = "SELECT {$this->table_lien_he}.*
                FROM	{$this->table_lien_he}                
                WHERE	status = ?
                ORDER BY id";

        return $this->query_array($sql, array($status));
    }
    public function getInforLienheById($id,$status=  AppContants::ACTIVE_STATUS){
        $sql = "SELECT {$this->table_lien_he}.*
                FROM	{$this->table_lien_he}                
                WHERE {$this->table_lien_he}.id = ?
                        AND status = ?";

        return $this->query_row($sql, array($id,$status));
    }
    public function updateLienhe($data, $id) {
        $where = "id = '$id'";
        $sql = $this->db->update_string($this->table_lien_he, $data, $where);
        return $this->db->query($sql);
    }
}
?>